<template>
    <el-dialog title="会员卡验证" :visible.sync="dialogPassword" append-to-body :modal="true" :close-on-click-modal="false">
        <div>
            <el-input v-model="password" 
                    type="password"
                    @keyup.enter.native="debouncedVerify"
                    :clearable="true"
                    placeholder="请输入会员卡密码" 
                    class="input-with-select"
            >
                <el-button slot="append" type="primary" @click="debouncedVerify">验证</el-button>
            </el-input>
            <div class="remark">

            </div>
        </div>
        
    </el-dialog>
</template>
<script>
import _ from 'lodash'
export default {
    data(){
        return{
            dialogPassword: false,
            password: '',
            card_id:null
        }
    },
    created(){
        this.debouncedVerify = _.debounce(this.onVerify, 500)
    },
    methods:{
        debouncedVerify() {

        },
        onCheck(card_id){
            this.card_id = card_id
            if(this.$setting.vipcard_pwd){
                this.dialogPassword = true
                return true
            }
            return false
        },
        onVerify(){
            this.$http.post('/api/member-cards/pwd/' + this.card_id, {pwd: this.password}).then(ret => {
                let {data} = ret
                this.$message(data)
                if (data.type === 'success') {
                    this.dialogPassword = false
                    this.password = ''
                    this.$emit('verify',true)
                }else{
                    this.$emit('verify',false)
                }
            })
        }
    }
}
</script>
<style lang="scss" scoped>
.remark{
    height: 30px;
}
</style>
